package com.jweb.framework.id;


public class SequenceFactory extends TableSequenceFactory {
	
	private int sequ ; 
	private long preVal ; // 
	private int next ; // 
	private long sufVal ; // 
	
	public SequenceFactory(){
		setStep(10);
	}
	
	public void setStep(int i){
		if(i<1){
			//return ;
		}
		this.sequ = i ;
		this.next = this.sequ + 1 ;
	}
	
	protected long[] internalGenerate(int sequ,String corpId) {
        if(sequ > 1){
            throw new IllegalArgumentException("step sequence cannot generate more than 1 id once.");
        }
        synchronized(this){
            if(true || (this.next > this.sequ) || (this.dateCutoff && this.table.getTimeService().isCutoff(5 , this.sufVal))){
                this.next = 1;
                long[] arr = super.internalGenerate(this.sequ,corpId);
                this.preVal = arr[0] ;
                this.sufVal = arr[1] ;
            }
            
            return new long[]{(this.preVal + this.next) , this.sufVal};
        }
    }
	
}
